<template>
  <div>
    <h1>文章信息</h1>
    <el-button type="primary" @click="openAdd">发布文章</el-button>
    <el-table
      :data="specialist"
      style="width: 100%">
      <el-table-column
        prop="fileId"
        label="fileId"
        width="180">
      </el-table-column>
      <el-table-column
        prop="fileAuthor"
        label="作者名称"
        width="180">
      </el-table-column>
      <el-table-column
        prop="fileTitle"
        label="标题"
        width="180">
      </el-table-column>
      <el-table-column
        prop="fileContents"
        label="内容"
        width="180">
      </el-table-column>
      <el-table-column
        prop="userId"
        label="上传人id"
        width="260">
      </el-table-column>
      <el-table-column
        prop="bbsLive"
        label="点赞量"
        width="260">
      </el-table-column>
      <el-table-column
        label="操作"
        width="260">
        <template slot-scope="scope" >
          <el-button type="primary" @click="delSpecialist(scope.row.fileId)">删除</el-button>
          <el-button type="primary" @click="updateSpecialist(scope.row)">修改</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-dialog
      title="添加/修改文章"
      :visible.sync="dialogVisible"
      width="60%">
      <el-form ref="form" :model="expert" label-width="80px">
        <el-form-item label="作者名称">
          <el-input v-model="expert.fileAuthor"></el-input>
        </el-form-item>
        <el-form-item label="标题">
          <el-input v-model="expert.fileTitle"></el-input>
        </el-form-item>
        <el-form-item label="内容">
          <el-input v-model="expert.fileContents"></el-input>
        </el-form-item>
        <el-form-item label="文件">
          <el-input v-model="expert.file"></el-input>

        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="addSpecialist">立即创建</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>

    <div class="block">
      <el-pagination
        :current-page="file.pagenum"
        :page-sizes="[2,3,1]"
        :page-size="file.pagenum"
        layout="total, sizes, prev, pager, next, jumper"
        :total="file.total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange">
      </el-pagination>
    </div>

  </div>
</template>
<script>
  import {filefindall,delSpecialist,addSpecialist} from '@/api/bbs'
  export default {
    data(){
      return{
        specialist:[],
        dialogVisible:false,
        expert:{},
        file: {
          pagenum :1,
          pagesize :3,
          total :0
        }
      }
    },
    mounted(){
      this.filefindall();
    },
    methods: {
      updateSpecialist(row){
        this.expert=row
        this.dialogVisible=true
      },
      addSpecialist(){
        addSpecialist(this.expert).then(res=>{
          alert(res.msg)
          this.expert={}
          this.dialogVisible=false
          this.filefindall()
        })
      },
      filefindall(){
        filefindall(this.file).then(res=>{
            console.log(res.data)
            this.specialist=res.data;
            this.file.total=res.total;
        })
      },
      delSpecialist(fileId){
        delSpecialist(fileId).then(res=>{
          alert(res.msg)
          location.reload();
        })
      },
      openAdd(){
        this.dialogVisible=true
      },
      handleSizeChange(val) {
       this.file.pagesize=val;
       this.filefindall();
      },
      handleCurrentChange(val) {
        this.file.pagenum=val;
        this.filefindall();
      }
    }
  }
</script>
<style>

</style>
